﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using QuBa.UI.Web.Models;

namespace Quba.Web.Exam.Controllers
{
    public class HomeController : Controller
    {
        #region Index Get
        public ActionResult Index()
        {
            ViewBag.Message = "QuBa Home Page";
            return View();
        }
        #endregion Index Get

        #region TestCode Post
        [HttpPost]
        public ActionResult TestCode(TestCodeModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.TestCode))
                {
                    ModelState.AddModelError("TestCode", "The Test Code field is required.");
                    return View("Index");
                }

                TempData["TestCode"] = model.TestCode;
                return View("Register");
            }
            catch (Exception)
            {
                return View("Index");
            }
            
        }
        #endregion TestCode Post

        #region Register Post
        [HttpPost]
        public ActionResult Register(RegisterModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Candidate))
                {
                    ModelState.AddModelError("Candidate", "The Candidate name field is required.");
                    return View("Register");
                }
                if (string.IsNullOrEmpty(model.Email))
                {
                    ModelState.AddModelError("Candidate", "The Email address field is required.");
                    return View("Register");
                }
                if (string.IsNullOrEmpty(model.Mobile))
                {
                    ModelState.AddModelError("Candidate", "The Mobile Number field is required.");
                    return View("Register");
                }
                TempData["CandidateName"] = model.Candidate;

                return RedirectToAction("Instruction");
            }
            catch (Exception)
            {
                return View("Index");
            }

        }
        #endregion Register Post

        #region Instruction Get
        [HttpGet]
        public ActionResult Instruction()
        {
            var viewModel = new InsructionModel();
            var items = new List<string> { "The accordion, autocomplete, and tabs widgets have also received huge accessibility improvements. In addition, we've improved the APIs of several widgets, making them easier to use and creating more consistency across plugins.", "jQuery UI is built for designers and developers alike. We've designed all of our plugins to get you up and running quickly while being flexible enough to evolve with your needs and solve a plethora of use cases. Play around with the demos and read through the API documentation to get an idea of what's possible.", "The spinner widget displays buttons to easily input numeric values via the keyboard or mouse. When used in combination with Globalize, the spinner supports numbers, currencies, and dates in hundreds of locales.", "Examples of the markup that can be used for buttons: A button element, an input of type submit and an anchor." };

            viewModel.InsructionItemList = items;
            viewModel.TestCode = (string) TempData["TestCode"];
            viewModel.CandidateName = (string)TempData["CandidateName"];

            return View("Instruction", viewModel);
        }
        #endregion Instruction Get


        #region Instruction Post
        [HttpPost]
        public ActionResult Instruction(InsructionModel models)
        {
            return RedirectToAction("Index");
        }
        #endregion Instruction Post
    }
}
